package com.health.memberbackstage.web;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.health.memberbackstage.pojo.R.Result;
import com.health.memberbackstage.pojo.R.ResultEnum;
import com.health.memberbackstage.pojo.Report;
import com.health.memberbackstage.service.ReportService;
import com.health.memberbackstage.utils.AuthenticationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/report")
public class ReportController {

    @Autowired
    private ReportService reportService;

    @GetMapping
    private Result findAll(){

        Long memberID = AuthenticationUtils.getMemberID();
        LambdaQueryWrapper<Report> qw = Wrappers.lambdaQuery(Report.class)
                .eq(Report::getMemberId, memberID);
        List<Report> reports = reportService.list(qw);

        if (reports != null){
            return Result.success(reports);
        }
        return Result.fail("查询失败");
    }
}
